const _ = require('lodash')
const fp = require('lodash/fp')

// chunk - 拆分数组
console.log(_.chunk([1, 2, 3, 4, 5, 6, 7], 3))
// [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7 ] ]
let chunk = fp.chunk(3)
console.log(chunk([1, 2, 3, 4, 5, 6, 7]))
// [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7 ] ]

// compact - 返回过滤假值后的数组
console.log(_.compact([1, 2, 3, 0, null, undefined, NaN, false, , 9]))
console.log(fp.compact([1, 2, 3, 0, null, undefined, NaN, false, , 9]))
// [ 1, 2, 3, 9 ]

// concat - 连接数组
console.log(_.concat([1, 2], 3, [4], [[5]], [[[6]]], [7, 8]))
// [ 1, 2, 3, 4, [ 5 ], [ [ 6 ] ], 7, 8 ]
let concat = fp.concat([2, 3])
console.log(concat(4, [5], [[3]]))
// [ 2, 3, 4 ]

// difference - 为第一个数组去除第二个数组中的值
console.log(_.difference([1, 2, 3, 4, 5], [2, 4]))
// [ 1, 3, 5 ]
let difference = fp.difference([1, 2, 3, 4, 5])
console.log(difference([1, 2]))
// [ 3, 4, 5 ]

// drop - 切除数组前面几个元素，不传默认1
console.log(_.drop([1, 2, 3, 4, 5])) //[ 2, 3, 4, 5 ]
console.log(_.drop([1, 2, 3, 4, 5], 0)) //[ 1, 2, 3, 4, 5 ]
console.log(_.drop([1, 2, 3, 4, 5], 1)) //[ 2, 3, 4, 5 ]
console.log(_.drop([1, 2, 3, 4, 5], 2)) //[ 3, 4, 5 ]
console.log(_.drop([1, 2, 3, 4, 5], 6)) //[]
let drop = fp.drop(3)
console.log(drop([5, 4, 3, 2, 1]))
// [ 2, 1 ]

// dropRight - 切除尾部几个元素，默认1
console.log(_.drop(['a', 'b'])) //[ 'b' ]
console.log(_.drop(['a', 'b'], 0)) //[ 'a', 'b' ]
let dropRight = fp.dropRight(2)
console.log(dropRight([5, 4, 6, 7, 8])) // [ 5, 4, 6 ]

// fill - 填充
console.log(_.fill([1, 2, 3], 'a')) //[ 'a', 'a', 'a' ]
let fill = fp.fill(1)
let fill1 = fill(5)
let fill2 = fill1('b')
let fill3 = fill2([1, 2, 3])
console.log(fill3) // [ 1, 'b', 'b' ]


// flattenDeep - 数组扁平化
console.log(_.flattenDeep([1, [2, [3, 4, [5]]]]))
console.log(fp.flattenDeep([1, [2, [3, 4, [5]]]]))

// fromPairs - 处理成键值对
console.log(_.fromPairs([['aaa', 111], ['bbb', 222]]))
console.log(fp.fromPairs([['aaa', 111], ['bbb', 222]]))
// { aaa: 111, bbb: 222 }

// initial - 删除最后一个元素
console.log(_.initial([3, 4, 5])) //[ 3, 4 ]
console.log(fp.initial([3, 4, 5])) //[ 3, 4 ]


// nth - 获取第n个元素
console.log(_.nth([1, 2, 3], 2)) // 3
console.log(fp.nth(1)([1, 2, 3])) // 2

